<template>
    <up-navbar title="拉新" :autoBack="true" bgColor="rgba(255,255,255,0)">

    </up-navbar>
    <view class="w-[100%] h-[100vh] relative overflow-hidden flex  flex-col justify-center items-center">
        <image src="@/static/images/index_bg/login_bg.png" class="w-[100%] h-[40vh] z-[-1] absolute top-0"></image>
        <view class="flex w-[100%] px-[60rpx] pb-[120rpx] flex-col justify-center items-center">
            <view class="w-[100%] flex mb-[150rpx] flex-col items-center justify-center">
                <up-avatar src="https://falvren.oss-cn-beijing.aliyuncs.com/2025040314415692669.jpg"
                    size="230rpx"></up-avatar>
                <view class="text-[32rpx] mt-[20rpx] font-[700]">
                    东元电竞俱乐部
                </view>
            </view>
            <view class="text-[32rpx] text-[red] mb-[30rpx]">
                {{ msg }}
            </view>
            <view class="text-[28rpx] text-[red] mb-[30rpx]">
                <view>管事邀请绑定新用户后，首次充值{{(firstRechargeAmount/100).toFixed(2)}}元以上赠送{{(cashback/100).toFixed(2)}}元可提现收益!</view>
				<view>打手邀请绑定新用户后，首次充值{{(firstRechargeAmount/100).toFixed(2)}}元以上赠送{{(thugCashback/100).toFixed(2)}}元可提现收益！</view>
            </view>
            <up-button text="立即绑定！" throttleTim="500" loadingText="正在绑定，请稍后" :loading="loginLoading" :color="themeColor"
                size="large" @click="vxLogin(null)">
            </up-button>
        </view>
    </view>
</template>
<script setup>
import { ref } from 'vue'
import { wxLogin, setNewUser, } from '@/api/oauth';
import { getWxCode } from '@/utils/geek';
import { onLoad, onShow, onUnload } from '@dcloudio/uni-app'
import { register_thug } from '@/api/login'
import { setToken } from '@/utils/auth';
import useUserStore from '@/store/modules/user';
import { getSystem_config}from '@/api/protocol.js'
const cashback=ref(0);
const firstRechargeAmount=ref(0)
const thugCashback =ref(0)
// 获取公告信息
const getAnn = () => {
    getSystem_config(1).then(response => {
        if (response.code == 200 && response.data && response.data.announcement) {
            cashback.value = response.data.cashback;
            firstRechargeAmount.value = response.data.firstRechargeAmount;
			thugCashback.value = response.data.thugCashback;
        }
    }).catch(error => {
        console.error('获取公告信息失败:', error);
    });
};
const userStore = useUserStore();
// 登录逻辑cc
const loginLoading = ref(false);
const msg = ref('')
const vxLogin = async (bdCode = null) => {
    const activationCode = bdCode || yqmCode.value
    loginLoading.value = true;
    await getWxCode()
        .then(async (code) => {
            const datas = {
                code,
                activationCode,
            };
            const data = await register_thug(datas).then(res => {
                msg.value = '绑定信息：' + res?.msg
                if (res.code == 200) {
                    uni.$u.toast('绑定成功，即将跳转至登录页面！');
                    setTimeout(() => {
                        loginLoading.value = false;
                        uni.reLaunch({
                            url: '/pages/login'
                        });
                    }, 1500);
                } else {
                    uni.hideLoading();
                    loginLoading.value = false;
                    uni.$u.toast(res?.msg);
                }
            })
        })
        .catch((e) => {
            uni.hideLoading();
            loginLoading.value = false;
            uni.$u.toast('绑定失败!');
        });
};
const yqmCode = ref(null);
onLoad((options) => {
    getAnn();
    const data = options.scene;
    console.log(options, 'options')
    if (data) {
        typeof data == 'string' ? yqmCode.value = data : typeof data == 'object' && data.code ? yqmCode.value = data.code : yqmCode.value = '';
        if (typeof data == 'string') return vxLogin(data);
        if (typeof data == 'object' && data.code) return vxLogin(data.code);
    } else {
        uni.$u.toast('绑定失败!未获取到邀请码');
    }
})
</script>
<style lang="scss">
Page,
body {
    background-color: rgb(244, 244, 244) !important;
}
</style>